package com.gs.synedocket.dialog;

import android.content.Context;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.gs.synedocket.R;
import com.gs.synedocket.util.CountDownTimerUtil;


public class WarningDialog extends BaseDialog {

    private Context context;
    private long countDown;
    private TextView tvTitle;
    private CountDownTimerUtil util;

    public WarningDialog(@NonNull Context context, long countDown, IDoneListener iDoneListener) {
        super(context, R.style.toast_dialog);
        this.context = context;
        this.countDown = countDown;
        this.iDoneListener = iDoneListener;
    }

    @Override
    public void refreshView() {
    }

    @Override
    public void initView() {
        tvTitle = findViewById(R.id.tvMsg);
        util = new CountDownTimerUtil(countDown, new CountDownTimerUtil.OnResponseListener() {
            @Override
            public void onTick(long millisUntilFinished) {
                tvTitle.setText(context.getString(R.string.countDown, millisUntilFinished / 1000));
            }

            @Override
            public void onFinish() {
                dismiss();
                iDoneListener.getDoneFromDialog();
            }
        });
    }

    public void cancelCountDown() {
        util.cancelCountDown();
    }


    @Override
    public int getLayoutId() {
        return R.layout.dialog_warning;
    }

    private IDoneListener iDoneListener;

    public interface IDoneListener {
        void getDoneFromDialog();
    }
}
